package org.fly.controller.wap;

import org.fly.bean.WxSetting;
import org.fly.controller.AbstractController;
import org.fly.service.WxSettingService;
import org.fly.utils.JsonUtils;
import org.fly.utils.StringUtil;
import org.fly.utils.wx.WxUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by rongzhao.zhu on 2018/4/22.
 */
@Controller
@RequestMapping("/wx/common/")
public class WxCommonController extends AbstractController {

    @Autowired
    WxSettingService wxSettingService;

    @RequestMapping(value = "/wx/getAuth", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Object getAuth(String recommendId,HttpServletRequest request)  {

        WxSetting wxSetting = wxSettingService.find();
        String backUrl = StringUtil.getDomain(request)+"/pages/wx/get_user_info.jsp";
        System.out.println("**********  "+backUrl);
        String redirectUrl = WxUtils.buildAuthUrl(wxSetting,backUrl,recommendId);
        return JsonUtils.encode(createDataTip(redirectUrl));
    }
}
